# Copyright 2010-2021, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
    "//:build_defs.bzl",
    "cc_binary_mozc",
    "cc_library_mozc",
    "cc_test_mozc",
    "objc_library_mozc",
    "py_binary_mozc",
    "py_library_mozc",
    "select_mozc",
)
load(
    "//:config.bzl",
    "LINUX_MOZC_BROWSER_COMMAND",
    "LINUX_MOZC_DOCUMENT_DIR",
    "LINUX_MOZC_SERVER_DIR",
)

package(default_visibility = [
    "//:__subpackages__",
])

exports_files([
    "client.h",
    "util.h",
])

# Test suite needs to have exact test names,
# because android tests are tagged "manual".
test_suite(
    name = "android_test",
    tests = [
        ":bitarray_test_android",
        ":clock_mock_test_android",
        ":clock_test_android",
        ":config_file_stream_test_android",
        ":cpu_stats_test_android",
        ":encryptor_test_android",
        ":hash_test_android",
        ":logging_test_android",
        ":mmap_test_android",
        ":number_util_test_android",
        ":obfuscator_support_test_android",
        ":process_mutex_test_android",
        ":scheduler_stub_test_android",
        ":scheduler_test_android",
        ":serialized_string_array_test_android",
        ":singleton_test_android",
        ":stopwatch_test_android",
        ":system_util_test_android",
        ":text_normalizer_test_android",
        ":thread_test_android",
        ":trie_test_android",
        ":unnamed_event_test_android",
        ":url_test_android",
        ":version_test_android",
        # Disabled tests due to errors.
        # ":embedded_file_test_android",
        # ":file_util_test_android",
        # ":multifile_test_android",
        # ":util_test_android",
    ],
)

cc_library_mozc(
    name = "base",
    hdrs = [
        "compiler_specific.h",
        "const.h",
    ],
    deps = [
        ":compiler_specific",
        ":const",
        ":file_stream",
        ":file_util",
        ":mmap",
        ":number_util",
        ":port",
        ":process_mutex",
        ":singleton",
        ":system_util",
        ":thread",
        ":util",
    ],
)

cc_library_mozc(
    name = "compiler_specific",
    hdrs = ["compiler_specific.h"],
    visibility = ["//visibility:private"],
)

cc_library_mozc(
    name = "init_mozc_buildtool",
    srcs = ["init_mozc.cc"],
    hdrs = ["init_mozc.h"],
    copts = ["-DMOZC_BUILDTOOL_BUILD"],
    visibility = ["//:__subpackages__"],
    deps = [
        "@com_google_absl//absl/flags:flag",
    ] + select_mozc(
        client = [
            ":file_util",
            ":logging",
            "@com_google_absl//absl/flags:parse",
        ],
        default = ["//base"],
    ),
)

cc_library_mozc(
    name = "init_mozc",
    srcs = ["init_mozc.cc"],
    hdrs = ["init_mozc.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        "@com_google_absl//absl/flags:flag",
    ] + select_mozc(
        client = [
            ":file_util",
            ":logging",
            ":system_util",
            "@com_google_absl//absl/flags:parse",
        ],
        default = ["//base"],
    ),
)

cc_library_mozc(
    name = "port",
    hdrs = ["port.h"],
    deps = select_mozc(
        default = [
            "//base:base",
            "//base:port",
        ],
        linux = ["@com_google_absl//absl/base:core_headers"],
        oss = ["@com_google_absl//absl/base:core_headers"],
    ),
)

cc_library_mozc(
    name = "const",
    hdrs = ["const.h"],
    visibility = ["//visibility:private"],
)

cc_library_mozc(
    name = "scoped_handle",
    srcs = ["scoped_handle.cc"],
    hdrs = ["scoped_handle.h"],
    visibility = ["//:__subpackages__"],
)

cc_library_mozc(
    name = "freelist",
    hdrs = ["freelist.h"],
    visibility = ["//:__subpackages__"],
    deps = [":port"],
)

cc_library_mozc(
    name = "logging",
    srcs = ["logging.cc"],
    hdrs = ["logging.h"],
    linkopts = select_mozc(
        # Android requires linking logging library.
        android = ["-llog"],
    ),
    deps = select_mozc(
        default = [
            "//base",
            "//base:logging_extensions",
            "@com_google_absl//absl/synchronization",
        ],
        linux = [
            ":clock",
            ":const",
            ":singleton",
            "@com_google_absl//absl/memory",
            "@com_google_absl//absl/strings",
        ],
        oss = [
            ":clock",
            ":const",
            ":singleton",
            "@com_google_absl//absl/memory",
            "@com_google_absl//absl/strings",
        ],
        wasm = [
            ":clock",
            ":const",
            ":singleton",
            "@com_google_absl//absl/memory",
            "@com_google_absl//absl/strings",
        ],
    ) + [
        ":port",
        "@com_google_absl//absl/flags:flag",
    ],
)

cc_test_mozc(
    name = "logging_test",
    size = "small",
    srcs = ["logging_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":logging",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "codegen_bytearray_stream",
    srcs = ["codegen_bytearray_stream.cc"],
    hdrs = ["codegen_bytearray_stream.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":port",
    ],
)

cc_test_mozc(
    name = "codegen_bytearray_stream_test",
    size = "small",
    srcs = ["codegen_bytearray_stream_test.cc"],
    requires_full_emulation = False,
    tags = ["no_android"],
    visibility = ["//visibility:private"],
    deps = [
        ":codegen_bytearray_stream",
        ":port",
        "//testing:gunit_main",
        "@com_google_absl//absl/memory",
    ],
)

cc_library_mozc(
    name = "unnamed_event",
    srcs = ["unnamed_event.cc"],
    hdrs = ["unnamed_event.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":logging",
        ":port",
        ":scoped_handle",
    ],
)

cc_test_mozc(
    name = "unnamed_event_test",
    size = "small",
    srcs = ["unnamed_event_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":logging",
        ":port",
        ":thread",
        ":unnamed_event",
        ":util",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "thread",
    srcs = ["thread.cc"],
    hdrs = ["thread.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":logging",
        ":port",
    ],
)

cc_test_mozc(
    name = "thread_test",
    size = "small",
    srcs = [
        "thread_test.cc",
    ],
    requires_full_emulation = False,
    deps = [
        ":thread",
        ":util",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "win_util",
    hdrs = ["win_util.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":port",
        "//testing:gunit_prod",
    ],
)

cc_library_mozc(
    name = "singleton",
    srcs = ["singleton.cc"],
    hdrs = ["singleton.h"],
    visibility = ["//:__subpackages__"],
    deps = ["@com_google_absl//absl/base"],
)

cc_test_mozc(
    name = "singleton_test",
    size = "small",
    srcs = ["singleton_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":singleton",
        ":thread",
        ":util",
        "//testing:gunit_main",
    ],
)

py_binary_mozc(
    name = "gen_character_set",
    srcs = ["gen_character_set.py"],
)

genrule(
    name = "character_set_data",
    srcs = [
        "//data/unicode:JIS0201.TXT",
        "//data/unicode:JIS0208.TXT",
    ],
    outs = ["character_set.inc"],
    cmd = ("$(location :gen_character_set)" +
           " --jisx0201file=$(location //data/unicode:JIS0201.TXT)" +
           " --jisx0208file=$(location //data/unicode:JIS0208.TXT)" +
           " --output=$@"),
    exec_tools = [":gen_character_set"],
    visibility = ["//visibility:private"],
)

cc_library_mozc(
    name = "double_array_def",
    hdrs = ["double_array.h"],
    deps = [
        ":port",
    ],
)

cc_library_mozc(
    name = "japanese_util_rule",
    srcs = ["japanese_util_rule.cc"],
    hdrs = ["japanese_util_rule.h"],
    visibility = ["//visibility:private"],
    deps = [":double_array_def"],
)

cc_library_mozc(
    name = "hash",
    srcs = ["hash.cc"],
    hdrs = ["hash.h"],
    deps = [
        ":port",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "hash_test",
    srcs = ["hash_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":hash",
        ":port",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "clock",
    srcs = ["clock.cc"],
    hdrs = ["clock.h"],
    deps = [
        ":port",
        ":singleton",
        "@com_google_absl//absl/time",
    ],
)

cc_test_mozc(
    name = "clock_test",
    srcs = ["clock_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":clock",
        ":clock_mock",
        ":port",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "japanese_util",
    srcs = [
        "japanese_util.cc",
    ],
    hdrs = ["japanese_util.h"],
    deps = [
        ":double_array_def",
        ":japanese_util_rule",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "japanese_util_test",
    size = "small",
    srcs = [
        "japanese_util_test.cc",
    ],
    requires_full_emulation = False,
    deps = [
        ":japanese_util",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "util",
    srcs = [
        "util.cc",
        ":character_set_data",
    ],
    hdrs = ["util.h"],
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        ":double_array_def",
        ":japanese_util",
        ":logging",
        ":port",
        "@com_google_absl//absl/numeric:bits",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test_mozc(
    name = "util_test",
    size = "small",
    srcs = [
        "util_test.cc",
    ],
    requires_full_emulation = False,
    deps = [
        ":compiler_specific",
        ":file_stream",
        ":file_util",
        ":logging",
        ":number_util",
        ":port",
        ":util",
        "//testing:gunit_main",
        "//testing:mozctest",
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "file_stream",
    srcs = ["file_stream.cc"],
    hdrs = ["file_stream.h"],
    visibility = ["//:__subpackages__"],
)

cc_binary_mozc(
    name = "text_converter_compiler",
    srcs = ["text_converter_compiler.cc"],
    tags = ["manual"],
    deps = [
        ":double_array_def",
        ":file_stream",
        ":init_mozc_buildtool",
        ":logging",
        ":util",
        "@com_google_absl//absl/flags:flag",
        # For OSS, darts is also required.
        # http://chasen.org/~taku/software/darts/
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "number_util",
    srcs = ["number_util.cc"],
    hdrs = ["number_util.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":double_array_def",
        ":japanese_util_rule",
        ":logging",
        ":port",
        ":util",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test_mozc(
    name = "number_util_test",
    size = "small",
    srcs = ["number_util_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":number_util",
        ":port",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "trie",
    hdrs = ["trie.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":logging",
        ":util",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "trie_test",
    size = "small",
    srcs = ["trie_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":trie",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "text_normalizer",
    srcs = ["text_normalizer.cc"],
    hdrs = ["text_normalizer.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":port",
        ":util",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "text_normalizer_test",
    size = "small",
    srcs = ["text_normalizer_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":text_normalizer",
        ":util",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "clock_mock",
    testonly = 1,
    srcs = ["clock_mock.cc"],
    hdrs = [
        "clock.h",  # For ClockInterface
        "clock_mock.h",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":port",
        ":util",
        "@com_google_absl//absl/time",
    ],
)

cc_test_mozc(
    name = "clock_mock_test",
    size = "small",
    srcs = ["clock_mock_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":clock_mock",
        ":util",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "bitarray",
    hdrs = ["bitarray.h"],
    visibility = ["//:__subpackages__"],
    deps = [":port"],
)

cc_test_mozc(
    name = "bitarray_test",
    size = "small",
    srcs = ["bitarray_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":bitarray",
        ":util",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "mmap",
    srcs = ["mmap.cc"],
    hdrs = ["mmap.h"],
    deps = [
        ":logging",
        ":port",
        ":scoped_handle",
        ":util",
    ],
)

cc_test_mozc(
    name = "mmap_test",
    size = "small",
    srcs = ["mmap_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":file_util",
        ":mmap",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/flags:flag",
    ],
)

cc_library_mozc(
    name = "environ",
    srcs = ["environ.cc"],
    hdrs = ["environ.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":singleton",
    ],
)

cc_library_mozc(
    name = "environ_mock",
    hdrs = ["environ_mock.h"],
    deps = [":environ"],
)

cc_library_mozc(
    name = "file_util",
    srcs = ["file_util.cc"],
    hdrs = ["file_util.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":file_stream",
        ":logging",
        ":mmap",
        ":port",
        ":scoped_handle",
        ":singleton",
        ":util",
        ":win_util",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library_mozc(
    name = "file_util_mock",
    hdrs = ["file_util_mock.h"],
    deps = [
        ":file_util",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test_mozc(
    name = "file_util_mock_test",
    size = "small",
    srcs = ["file_util_mock_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":file_util_mock",
        "//testing:gunit_main",
    ],
)

cc_test_mozc(
    name = "file_util_test",
    size = "small",
    srcs = ["file_util_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":file_util",
        ":logging",
        ":number_util",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library_mozc(
    name = "system_util",
    srcs = ["system_util.cc"] + select_mozc(
        android = ["android_util.cc"],
    ),
    hdrs = ["system_util.h"] + select_mozc(
        android = ["android_util.h"],
    ),
    local_defines = select_mozc(
        linux = [
            "MOZC_DOCUMENT_DIR=\\\"" + LINUX_MOZC_DOCUMENT_DIR + "\\\"",
            "MOZC_SERVER_DIR=\\\"" + LINUX_MOZC_SERVER_DIR + "\\\"",
        ],
    ),
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        ":const",
        ":environ",
        ":file_util",
        ":logging",
        ":port",
        ":singleton",
        ":util",
        ":win_util",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/synchronization",
    ] + select_mozc(
        android = [
            # android_util.h includes this for FRIEND_TEST
            "//testing:gunit_prod",
        ],
        ios = [":mac_util"],
    ),
)

cc_test_mozc(
    name = "system_util_test",
    srcs = ["system_util_test.cc"],
    requires_full_emulation = False,
    visibility = ["//visibility:private"],
    deps = [
        ":environ_mock",
        ":file_util",
        ":file_util_mock",
        ":port",
        ":system_util",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "process",
    srcs = ["process.cc"],
    hdrs = ["process.h"],
    local_defines = [
        "MOZC_BROWSER_COMMAND=\\\"" + LINUX_MOZC_BROWSER_COMMAND + "\\\"",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":const",
        ":file_util",
        ":logging",
        ":port",
        ":scoped_handle",
        ":system_util",
        ":util",
        ":win_util",
        "@com_google_absl//absl/strings",
    ] + select_mozc(
        macos = ["mac_process"],
    ),
)

objc_library_mozc(
    name = "mac_process",
    srcs = select_mozc(macos = ["mac_process.mm"]),
    hdrs = select_mozc(macos = ["mac_process.h"]),
    deps = [
        ":mac_util",
        ":util",
    ],
)

cc_binary_mozc(
    name = "process_main",
    srcs = ["process_main.cc"],
    deps = [
        ":init_mozc",
        ":logging",
        ":process",
        "@com_google_absl//absl/flags:flag",
    ],
)

cc_library_mozc(
    name = "process_mutex",
    srcs = ["process_mutex.cc"],
    hdrs = ["process_mutex.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":file_util",
        ":logging",
        ":port",
        ":scoped_handle",
        ":singleton",
        ":system_util",
        ":util",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_test_mozc(
    name = "process_mutex_test",
    size = "small",
    srcs = ["process_mutex_test.cc"],
    requires_full_emulation = False,
    deps = [
        "logging",
        ":file_util",
        ":process_mutex",
        ":system_util",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/status",
    ],
)

cc_library_mozc(
    name = "run_level",
    srcs = [
        "run_level.cc",
        "win_sandbox.h",
    ],
    hdrs = ["run_level.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":const",
        ":logging",
        ":port",
        ":scoped_handle",
        ":system_util",
        ":util",
        ":win_util",
    ],
)

cc_binary_mozc(
    name = "run_level_main",
    srcs = ["run_level_main.cc"],
    deps = [
        ":init_mozc",
        ":run_level",
        "@com_google_absl//absl/flags:flag",
    ],
)

py_library_mozc(
    name = "gen_config_file_stream_data_lib",
    srcs = ["gen_config_file_stream_data.py"],
)

py_binary_mozc(
    name = "gen_config_file_stream_data",
    srcs = ["gen_config_file_stream_data.py"],
    deps = [":gen_config_file_stream_data_lib"],
)

genrule(
    name = "config_file_stream_data",
    srcs = [
        "//data/keymap:atok.tsv",
        "//data/keymap:chromeos.tsv",
        "//data/keymap:kotoeri.tsv",
        "//data/keymap:mobile.tsv",
        "//data/keymap:ms-ime.tsv",
        "//data/preedit:composition_table",
    ],
    outs = ["config_file_stream_data.inc"],
    cmd = "$(location :gen_config_file_stream_data) --output=$@ $(SRCS)",
    exec_tools = [":gen_config_file_stream_data"],
    visibility = ["//visibility:private"],
)

cc_library_mozc(
    name = "config_file_stream",
    srcs = [
        "config_file_stream.cc",
        ":config_file_stream_data",
    ],
    hdrs = ["config_file_stream.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":file_stream",
        ":file_util",
        ":logging",
        ":port",
        ":singleton",
        ":system_util",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "config_file_stream_test",
    size = "small",
    srcs = ["config_file_stream_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":config_file_stream",
        ":file_util",
        ":system_util",
        "//testing:gunit_main",
        "@com_google_absl//absl/flags:flag",
    ],
)

TARGET_PLATFORM = select_mozc(
    android = "Android",
    chromiumos = "ChromeOS",
    default = "",
    linux = "Linux",
    macos = "Mac",
    wasm = "Wasm",
    windows = "Windows",
)

genrule(
    name = "mozc_version_txt",
    srcs = [
        "//data/version:mozc_version_template.bzl",
    ],
    outs = ["mozc_version.txt"],
    cmd = ("$(location //build_tools:mozc_version)" +
           ' --template_path="$(location //data/version:mozc_version_template.bzl)"' +
           ' --output="$(OUTS)"' +
           " --target_platform=" + TARGET_PLATFORM),
    exec_tools = ["//build_tools:mozc_version"],
    visibility = ["//:__subpackages__"],
)

genrule(
    name = "version_def_h",
    srcs = [
        "mozc_version.txt",
        "version_def_template.h",
    ],
    outs = ["version_def.h"],
    cmd = ("$(location //build_tools:replace_version)" +
           " --version_file=$(location mozc_version.txt) " +
           " --input=$(location version_def_template.h) --output=$(OUTS)" +
           " --branding=Mozc"),
    exec_tools = ["//build_tools:replace_version"],
    visibility = ["//visibility:private"],
)

cc_library_mozc(
    name = "version",
    srcs = [
        "version.cc",
        ":version_def_h",
    ],
    hdrs = [
        "version.h",
        "version_def.h",
    ],
    deps = [
        ":logging",
        ":number_util",
        ":port",
        ":util",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "version_test",
    size = "small",
    srcs = ["version_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":util",
        ":version",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library_mozc(
    name = "obfuscator_support",
    srcs = [
        "unverified_aes256.cc",
        "unverified_sha1.cc",
    ],
    hdrs = [
        "unverified_aes256.h",
        "unverified_sha1.h",
    ],
    visibility = [
        "//data_manager:__pkg__",
        "//ipc:__pkg__",
    ],
    deps = [
        ":logging",
        ":port",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "obfuscator_support_test",
    size = "small",
    srcs = [
        "unverified_aes256_test.cc",
        "unverified_sha1_test.cc",
    ],
    requires_full_emulation = False,
    visibility = ["//visibility:private"],
    deps = [
        ":obfuscator_support",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
    ],
)

# TODO(team): encryptor.cc and password_manager.cc are mutually dependent and
# cannot be decoupled.  Fix this issue.
cc_library_mozc(
    name = "encryptor",
    srcs = [
        "encryptor.cc",
        "password_manager.cc",
    ],
    hdrs = [
        "encryptor.h",
        "password_manager.h",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":const",
        ":file_stream",
        ":file_util",
        ":logging",
        ":mmap",
        ":obfuscator_support",
        ":port",
        ":singleton",
        ":system_util",
        ":util",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/strings:str_format",
    ] + select_mozc(
        ios = [":mac_util"],
    ),
)

cc_test_mozc(
    name = "encryptor_test",
    size = "small",
    srcs = [
        "encryptor_test.cc",
        "password_manager_test.cc",
    ],
    requires_full_emulation = False,
    visibility = ["//visibility:private"],
    deps = [
        ":encryptor",
        ":system_util",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/flags:flag",
    ],
)

cc_binary_mozc(
    name = "encryptor_main",
    srcs = ["encryptor_main.cc"],
    visibility = ["//visibility:private"],
    deps = [
        ":encryptor",
        ":file_util",
        ":init_mozc",
        ":logging",
        ":status",
        ":util",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/strings",
    ],
)

cc_binary_mozc(
    name = "password_manager_main",
    srcs = ["password_manager_main.cc"],
    visibility = ["//visibility:private"],
    deps = [
        ":encryptor",
        ":init_mozc",
        ":logging",
        ":util",
        "@com_google_absl//absl/flags:flag",
    ],
)

cc_library_mozc(
    name = "scheduler",
    srcs = [
        "scheduler.cc",
    ],
    hdrs = ["scheduler.h"],
    deps = [
        ":clock",
        ":logging",
        ":port",
        ":singleton",
        ":thread",
        ":unnamed_event",
        ":util",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_test_mozc(
    name = "scheduler_test",
    size = "small",
    srcs = ["scheduler_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":logging",
        ":scheduler",
        ":unnamed_event",
        ":util",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "scheduler_stub",
    testonly = 1,
    srcs = ["scheduler_stub.cc"],
    hdrs = ["scheduler_stub.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":logging",
        ":port",
        ":scheduler",
    ],
)

cc_test_mozc(
    name = "scheduler_stub_test",
    size = "small",
    srcs = ["scheduler_stub_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":scheduler_stub",
        "//testing:gunit_main",
    ],
)

cc_library_mozc(
    name = "cpu_stats",
    srcs = ["cpu_stats.cc"],
    hdrs = ["cpu_stats.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":logging",
        ":port",
    ],
)

cc_test_mozc(
    name = "cpu_stats_test",
    size = "small",
    srcs = ["cpu_stats_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":cpu_stats",
        "//testing:gunit_main",
    ],
)

cc_binary_mozc(
    name = "cpu_stats_main",
    srcs = ["cpu_stats_main.cc"],
    deps = [
        ":cpu_stats",
        ":init_mozc",
        ":port",
        ":thread",
        ":util",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/memory",
    ],
)

cc_library_mozc(
    name = "stopwatch",
    srcs = ["stopwatch.cc"],
    hdrs = ["stopwatch.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":clock",
        ":port",
    ],
)

cc_test_mozc(
    name = "stopwatch_test",
    size = "small",
    srcs = ["stopwatch_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":clock",
        ":clock_mock",
        ":stopwatch",
        "//testing:gunit_main",
        "@com_google_absl//absl/memory",
    ],
)

cc_binary_mozc(
    name = "stopwatch_main",
    srcs = ["stopwatch_main.cc"],
    deps = [
        ":init_mozc",
        ":stopwatch",
        ":util",
        "@com_google_absl//absl/flags:flag",
    ],
)

cc_library_mozc(
    name = "url",
    srcs = ["url.cc"],
    hdrs = ["url.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":logging",
        ":port",
        ":singleton",
        ":util",
        ":version",
    ],
)

cc_test_mozc(
    name = "url_test",
    size = "small",
    srcs = ["url_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":url",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "multifile",
    srcs = ["multifile.cc"],
    hdrs = ["multifile.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":file_stream",
        ":logging",
        ":port",
        ":util",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "multifile_test",
    size = "small",
    srcs = ["multifile_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":file_stream",
        ":file_util",
        ":multifile",
        ":util",
        "//testing:gunit_main",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library_mozc(
    name = "coordinates",
    hdrs = ["coordinates.h"],
    visibility = ["//:__subpackages__"],
)

cc_library_mozc(
    name = "crash_report_handler",
    srcs = ["crash_report_handler.cc"],
    hdrs = ["crash_report_handler.h"],
    deps = [
        ":base",
        ":file_util",
        ":logging",
        ":system_util",
        ":util",
        ":version",
    ],
)

objc_library_mozc(
    name = "mac_util",
    srcs = [
        "mac_util.mm",
        "scoped_cftyperef.h",
    ],
    hdrs = ["mac_util.h"],
    sdk_frameworks = [
        "CoreGraphics",
        "CoreServices",
        "IOKit",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":const",
        ":logging",
        ":port",
        ":singleton",
        "@com_google_absl//absl/strings",
    ],
)

# Only for macOS.
cc_binary_mozc(
    name = "mac_util_main",
    srcs = [
        "mac_util.h",
        "mac_util_main.cc",
    ],
    deps = [
        ":init_mozc",
        ":port",
        ":util",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/strings",
    ] + select_mozc(ios = [":mac_util"]),
)

cc_library_mozc(
    name = "winmain",
    hdrs = ["winmain.h"],
    visibility = [
        # For //server:mozc_server.
        "//server:__pkg__",
    ],
    deps = [
        ":base",
        ":port",
        ":util",
    ],
)

cc_library_mozc(
    name = "win_api_test_helper",
    hdrs = ["win_api_test_helper.h"],
    visibility = [
        # For //config:stats_config_util_test.
        "//config:__pkg__",
    ],
    deps = [":port"],
)

cc_library_mozc(
    name = "embedded_file",
    hdrs = ["embedded_file.h"],
    visibility = ["//:__subpackages__"],
    deps = [
        ":port",
        "@com_google_absl//absl/strings",
    ],
)

genrule(
    name = "gen_embedded_file_test_data",
    srcs = ["embedded_file.h"],
    outs = ["embedded_file_test_data.inc"],
    cmd = "$(location //build_tools:embed_file) --input=$< --name=kEmbeddedFileTestData --output=$@",
    exec_tools = ["//build_tools:embed_file"],
)

cc_test_mozc(
    name = "embedded_file_test",
    srcs = [
        "embedded_file_test.cc",
        ":gen_embedded_file_test_data",
    ],
    data = ["embedded_file.h"],
    requires_full_emulation = False,
    deps = [
        ":embedded_file",
        ":file_util",
        ":port",
        "//testing:gunit_main",
        "//testing:mozctest",
    ],
)

cc_library_mozc(
    name = "serialized_string_array",
    srcs = ["serialized_string_array.cc"],
    hdrs = ["serialized_string_array.h"],
    deps = [
        ":file_util",
        ":logging",
        ":port",
        ":status",
        ":util",
        "@com_google_absl//absl/strings",
    ],
)

cc_test_mozc(
    name = "serialized_string_array_test",
    srcs = ["serialized_string_array_test.cc"],
    requires_full_emulation = False,
    deps = [
        ":port",
        ":serialized_string_array",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
    ],
)

cc_library_mozc(
    name = "status",
    hdrs = ["status.h"],
    deps = [
        ":logging",
    ],
)
